/* 装饰器模式 */

/// 饮料
pub trait Drink {
    fn get_price(&self) -> u32;
}

/// 奶茶
pub struct MilkTea {
    cup: u8 // 1 小杯，2中杯，3大杯
}

impl Drink for MilkTea {
    fn get_price(&self) -> u32 {
        self.cup as u32 * 5
    }
}

/// 珍珠奶茶
pub struct BubbleTea {
    milk_tea: MilkTea
}

impl Drink for BubbleTea {
    fn get_price(&self) -> u32 {
        return self.milk_tea.get_price() + 5
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_decorator_1() {
        let milk_tea = MilkTea{
            cup: 2 // 中杯
        };

        // 中杯奶茶的价格是10元
        assert_eq!(10, milk_tea.get_price());

        let bubble_tea = BubbleTea{
            milk_tea: milk_tea
        };

        // 中杯珍珠奶茶的价格是奶茶的10元+珍珠5元=15元
        assert_eq!(15, bubble_tea.get_price());
    }
}